<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>制作采购成本清单</title>
<link href="/res/css/respective/priceAsk/buyer.css" rel="stylesheet">
    <script src="/res/js/common/jquery.1.9.1.min.js"></script>
	<style>
.backcontent .backfoot {
	padding-left: 0px;
}
.city-picker-span{
	width: 245px;
    height: 32px;
    line-height: 31px;
    border: 1px solid #e9e9e9;
    padding-left: 15px;
    display: inline-block;
}
.table>tbody>tr>td.setred{
    color: red;
}
</style>
</head>
<body>
	<div class="warp">
		[#include "/front/common/front_headAzt.html"]
		<div class="backcontent"> 
			<div class="back-main">
				<div class="mainContent">
		 			<div class="createOp">
						<h1 style="margin-top: 48px;">制作采购成本清单</h1>
						<div class="juZhong">
							<div style="padding: 35px 70px;background: white;">
                                <input type="hidden" value="${enqid!}" id="enqid"  >
								[#list createList as create]

								<div class="form-group itermTitle">
									<label style="text-align: left;">${create.categoryName!}</label>
									<small class="itermTitleIntr">价格最低将被<span style="margin-left: 0px;">标红</span>，选择到合适的报价后可以勾选此供应商的报价在页面下方点击下单购买</small>
									<hr></hr>
								</div>
								<table class="table bordered">
									<thead>
										<tr>
											<th rowspan="2">询价产品</th>
											<th>供应商报价</th>
										</tr>
										<tr>
											[#list create.company as cp]
											<th>
												<img class="image" atttotal="${cp.totalPrice!}" attquoteid="${cp.quoteid!}" attcategory="${cp.categorySId}"    src="/res/images/checkBoxRadio/noCheck.png" onclick="choose(this,${create.categoryid})"/>
												<span>${cp.companyName!}</span>
												<h5 >
													<small class="billPrice">清单报价：</small>${cp.totalPrice?string("currency")}
												</h5>
											</th>
											[/#list]
										</tr> 
									</thead>
									<tbody>
									<!--默认显示8行-->
									[#list create.products as product]
									<tr class="product" attnum="${product_index}" attp="${create_index}" >
										<td>
											${product.productName!}${product.quantity!}${product.unit!}
										</td>

										[#list create.company as cp]
										<td class="price_${product_index}"  id="company_${create_index}_${product_index}_${cp_index}"   attprice="[#if cp.price[product_index]??]${cp.price[product_index]}[/#if]" >
											[#if cp.price[product_index]??]
												￥${cp.price[product_index]?string("##,##0.00")}
											[#else ]
												/
											[/#if]
										</td>
										[/#list]
									</tr>
									[/#list]
								</tbody> 
								[#if create_index==createList?size-1]
								<tfoot>
									<tr class="tableBorde">
										<td class="fenye" colspan="200"
											style="text-align: right; background: #f8f8f8;padding: 20px 15px;">下单商品总价：&nbsp;&nbsp;&nbsp;
											<span id="totalPrice" class="contentBold" style="font-size: 18px;">￥0.00</span>
											<input type="hidden" id="total">
										</td>
									</tr> 
								</tfoot>
								[/#if]
								</table>
								[/#list]
								<div style="height: 45px;">
									<button class="backButt" type="button" onclick="location.href='/enquiry/purchase/quote/detail/${enqid}'" >返回报价清单</button>
									[#--<button class="buyButt" onclick="gobuy()"  type="button" style="float: right;">下单购买</button>--]
									<button onclick="subBudget()"   class="backButt" style="float: right;" type="button">生成采购成本</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- 底部菜单-->
			[#include "/front/common/front_footerAzt.html"]
		</div>
 
	</div>

    <script src="/res/third/layer/layer.js"></script>
    <script src="/res/third/layer/layer.extends.js"></script>
	<script src="/res/js/structure/struture.js"></script> 
	<script src="/res/js/common/common.js"></script>
	<script type="text/javascript">
$(function(){
	var col=$(".table.bordered tr:eq(1)").children("th").size();
	//$(".table.bordered tr:eq(0)").children("th:eq(1)").attr("colspan",col);
	$(".table.bordered").each(function(){
		$(this).find("tr:eq(0)").children("th:eq(1)").attr("colspan",col);
	});
})


/*确定最低价格*/
$(".product").each(function (i) {
	//每行循环一次
	var attnum = $(this).attr("attnum");
	var attp = $(this).attr("attp");
	var minprice=null;
	var minidex =null;//最小值序号
    //用以分辨出价格相同的
	var pricecount=0;//有价格的总数量
	var pricedif=0;//有差价的数量

	//该行下的价格列进行比较
	$(this).find(".price_"+attnum).each(function (j) {
		var price = $(this).attr("attprice");
		if(price!=""){
            pricecount++;
			var pf = parseFloat(price);
			if(minprice==null){
				minprice =pf;
                minidex=j;
                pricedif++;
			}else{
				if(minprice > pf){
                    minidex=j;
					minprice=pf;
                    pricedif++;
				}else if(minprice < pf){
                    pricedif++;
				};
			}
		}

    });

    if( minprice!=null && ( pricecount ==1 || ( pricecount > 1 && pricedif > 1 )) ){
        $("#company_"+attp+"_"+attnum+"_"+minidex).addClass("setred");
    }
});



  function choose(img,cid){
		var total=0.0;
		if($(img).hasClass("imgchecked")){
            $(img).removeClass("imgchecked imgchecked_"+cid).attr("src","/res/images/checkBoxRadio/noCheck.png");
		}else{
            $(".imgchecked_"+cid).each(function () {
                $(this).removeClass("imgchecked imgchecked_"+cid).attr("src","/res/images/checkBoxRadio/noCheck.png");
            });
            $(img).attr("src","/res/images/checkBoxRadio/blueCheck.png");
            $(img).addClass("imgchecked imgchecked_"+cid);
		}

		$(".imgchecked").each(function () {
			var atttotal = $(this).attr("atttotal");
			total=total+parseFloat(atttotal);
		});
		$("#totalPrice").text($.my.currency(total,true));		//赋给页面加上$用来显示
		$("#total").val(total);	//赋给隐藏input用来提交
	}

	
	function gobuy() {
/*        var checkedsize = $(".imgchecked").size();
        if(checkedsize==0){
            layer.msgShort("至少选择一个");
        }else{
            var d = [];
            $(".imgchecked").each(function () {
                //报价id   类目id
                var quoteid = $(this).attr("attquoteid");
                var attcategory = $(this).attr("attcategory");
                var obj ={quoteid:quoteid,categoryId:attcategory};
                qcats.push(obj);
            });
		}*/
    }

	function subBudget() {
		var checkedsize = $(".imgchecked").size();
		if(checkedsize==0){
			layer.msgShort("至少选择一个");
		}else{
			var qcats = [];
			$(".imgchecked").each(function () {
					//报价id   类目id
					var quoteid = $(this).attr("attquoteid");
					var attcategory = $(this).attr("attcategory");
					var obj ={quoteid:quoteid,categoryId:attcategory};
                	qcats.push(obj);
            });
            var data ={checked:qcats,enqid:$("#enqid").val()};
			layer.post({
				url:"/enquiry/budget/purchase/create/save",
				data:JSON.stringify(data),
				contentType:"application/json",
				success:function (data) {
					if(data.success){
						layer.alert("制作采购成本清单成功",function () {
							location.href="/enquiry/budget/detail/"+data.obj+"/t/2"
                        });
					}else{
						layer.msgShort(data.msg);
					}
                }
			})

		}
    }

	</script>
</body>
</html>
